/**
 * 
 * purpose: LOGIN PANEL VIEW...
 * @auth: Ning
 * date: 2009-9-23
 * 
 * */
package string
{
	public class ExtendString
	{
		//START...
		
		//remove blank before and after string...
		public static function trim(str:String):String
		{
			
			str = str.replace(/^\s*/,"");

			str = str.replace(/\s*$/,"");
			
			return str;			
			
		}
		
		// string variables...
		public static function setStringVars(model:String,vars:Object):String
		{
			
			var pattern:RegExp = /\$\{([\w\d]+)\}/gi;
					
			var result:Array;

			do
			{
												
				result = pattern.exec(model);
								
				if(result is Array)
				{
					
					var replace:String = vars.hasOwnProperty(result[1]) ? String(vars[result[1]]) : "";	
					
					model = model.slice(0,pattern.lastIndex - result[0].toString().length) + replace + model.slice(pattern.lastIndex,model.length);	
					
					pattern.lastIndex = pattern.lastIndex - result[0].toString().length + replace.length;
						
				}
					

			}while(result);
						
			return model;
						
		}
		
		
		//END...
	}
}